package com.interview.javabasic.Sort;/*
@李子宁
Happy,happy everyday!
冲鸭！
*/

import javafx.scene.input.DataFormat;

import javax.xml.crypto.Data;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Date;

public class SelectSort {
    public static void main(String[] args) {
        int[] arr = {101,24,119,1,-1,90,123};
        Date date = new Date();
        LocalDateTime now = LocalDateTime.now();
        System.out.println("排序前：");
        System.out.println(Arrays.toString(arr));
        System.out.println(now);
        selectSort(arr);
        LocalDateTime now1 = LocalDateTime.now();
        System.out.println("排序后：");
        System.out.println(Arrays.toString(arr));
        System.out.println(now1);

    }

    public static void selectSort(int arr[]){
        boolean flag = false;
        for (int i = 0; i < arr.length - 1; i++) {
            int minIndex = i;
            int min = arr[i];
            for (int j = i + 1; j < arr.length; j++) {
            if (min > arr[j]){
                flag = true;
                min = arr[j];
                minIndex = j;
            }
        }
            if (minIndex!=i){
                arr[minIndex] = arr[i];
                arr[i] = min;
            }
            System.out.printf("第%d轮排序\n",i+1);
            System.out.println(Arrays.toString(arr));
            if (!flag){
                break;
            }else{
                flag = false;
            }
        }

    }
}
